const express = require('express');
const fs = require('fs');
const app = express();

/**
 * 引入路由文件
 * @param { String } fileUri 路由文件
 * @param { String } serviceName 服务前缀
 */
exports.routeService = function (fileUri, serviceName) {
  let routeArray = [];
  fs.readdir(fileUri, (err, files) => {
    if (!err) {
      files.forEach((i) => {
        routeArray.push(require(`${fileUri}/${i}`));
      });
      app.use(`/${serviceName}`, routeArray);
    }
  });
};
